Changes to copy(), shallowCopy(), and deepCopy()

In previous releases, shallowCopy() made a bitwise copy of an object, and deepCopy() first made a shallow copy of an object, and then called the virtual function deepenShallowCopy() to convert the shallow copy to a deep copy. Each class reimplemented deepenShallowCopy() to handle any pointer member variables contained in instances of its class.

The problems with this approach are that (1) it is usually unsafe to make a shallow copy of an object that contains pointers, and (2) with Release 2.0 of the AT&T C++ Translator, objects may contain compiler-generated pointers which deepenShallowCopy() cannot handle easily and portably.

The following changes have been made in an attempt to solve these problems:

Each class now reimplements the virtual function shallowCopy() to call the initialization constructor X::X(const X&) to make a shallow copy of an object. The implementation of shallowCopy() is the same for all classes and is generated automatically by the DEFINE_CLASS macro:

Object* classname::shallowCopy()

{

return new classname(*this);

}

Object::deepCopy() still calls the virtual function deepenShallowCopy() to convert a shallow copy, now made by the initialization constructor, to a deep copy. Since the shallow copy is no longer a simple bitwise copy, you may need to change deepenShallowCopy() for some classes.

In previous releases, copy() defaulted to deepCopy() since it was unsafe for general use. Beginning with this release, copy() defaults to shallowCopy() as it does in Smalltalk-80. Also, Object::deepCopy() is no longer a virtual function.